/**
 * Exam No: Y8467136
 */
package japrc2011;
import javax.swing.table.AbstractTableModel;

public class MapTableModel extends AbstractTableModel {
/*	String[] columnNames = {"","",""};
    Object [] [] currentMapView = {
            {"","",""},
            {"","",""},
            {"","",""},        
    };*/
		static int mapx = 3;
		static int mapy = 3;
        String[] columnNames = new String[mapy];
        Object [] [] currentMapView = new Object [mapx][mapy];
        
        public MapTableModel() //constructor in which the array is initialised
        {
        	mapx = getMapx();
        	mapy = getMapy();
        	for(int i=0; i<mapy; i++)
        	columnNames[i] = "";
        	for(int k=0; k<mapx; k++)
        	{
        		for(int l=0; l<mapy; l++)
        		{
        			currentMapView [k][l]= "";
        		}
        	}
        } 

        public int getColumnCount() {
            //return columnNames.length;
        	return mapy;
        }

        public int getRowCount() {
            //return currentMapView.length;
        	return mapx;
        }

        public String getColumnName(int col) {
            return columnNames[col];
        }

        public Object getValueAt(int row, int col) {
            return currentMapView[row][col];
        }

        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }
        
        public boolean isCellEditable(int row, int col) {
            return false;
        }

        public void setValueAt(Object value, int row, int col) {
            currentMapView[row][col] = value;
            fireTableCellUpdated(row, col); //Update of specified cell.
        }        
        
        public void setAllCells(Object [] [] newMapView)
        {
        	System.out.println("Kaleitai h setAllCells!!!");
            currentMapView = newMapView;
            fireTableDataChanged(); //Update of entire table (data only).
        }

        //getter
		public static int getMapx() {
			return mapx;
		}

		//setter 
		public void setMapx(int x) {
			mapx = x;
		}

		//getter
		public static int getMapy() {
			return mapy;
		}

		//setter
		public void setMapy(int y) {
			mapy = y;
		}
}

